<?php
include "work_exec.php";

echo "Please input jf url:";
$url = trim(fgets(STDIN));
$ishttp = true;
if(!strstr(strtolower($url),"http"))
{
$ishttp = false;
}
if($ishttp) {
$filename = substr($url,strrpos($url,"/")+1);
}
else {
$filename = trim($url);
}
$oldfileexists = file_exists($filename);
$c1 = "";
if($oldfileexists) {
	echo "overried? ([n]/y):";
	$c1 = trim(fgets(STDIN));
}
else
{
	$c1 = 'y';
}
if($ishttp && $c1 == 'y') {
if(file_exists($filename))
{
	unlink($filename);
}
$downloadcmd = 'lftp -c "pget -n 5 wget ' . $url . '" 2>&1';
if($ishttp) {
echo $downloadcmd . "\r\n";
proc_exec($downloadcmd);
}
}

$unlockcmd = 'security unlock-keychain -p b17h6c28 ${HOME}/Library/Keychains/login.keychain';
passthru($unlockcmd);
$signcmd = './resign.sh -o ~/pub/ -s "iPhone Distribution: YiZhi  Information Technology Co.,Ltd." -m AllAppInHouse.mobileprovision ' . $filename;
echo $signcmd . "\r\n";
passthru($signcmd);
$rfilename = str_replace('.ipa','-resigned.ipa',$filename);
$notes = "用itools下载下面的链接安装。\r\n\r\n";
$notes .= "http://www.itools.cn/download\r\n";

$notes .= "下面2个地址都可以下载，请选择速度快的一个下载：\r\n";


$notes .= "http://61.145.118.194:9090/pub/" . $rfilename . "\r\n";
$notes .= "ftp://smartmz:123789@192.95.33.31/pub/" . $rfilename . "\r\n";


$notes .= "\r\n*此链接请勿外传，否则签名失效，会导致游戏无法进入。\r\n";
echo $notes;
